interface CachProps{
    [key:string]:Array<((data:unknown)=>void)>
}
class Observe{
    private caches:CachProps = {}
    on(eventName:string,fn:((data:unknown)=>void)){
        this.caches[eventName] = this.caches[eventName] || []
        this.caches[eventName].push(fn)
    }
    emit(eventName:string,data?:unknown){
        if(this.caches[eventName]){
            this.caches[eventName].forEach((fn:(data:unknown)=>void)=>fn(data))
        }
    }
    off(eventName:string,fn?:((data:unknown)=>void)){
        if(this.caches[eventName]){
            let newCaches = fn?this.caches[eventName].filter(e=>e!==fn):[]
            this.caches[eventName] = newCaches
        }
    }
}